<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$goods = M('g_goods')->select();
    	$pic = M('g_goods_pic')->select();
    	foreach($goods as $k=>&$v){
    		$v['position'] = json_decode($v['position']);
    		foreach($pic as $key=>$val){
    			if($v['id']==$val['gid'] && $val['goods_zpic']==1){
    					$v['pic']=$val['goods_pic'];
    			}
    			if($v['id']==$val['gid'] && $val['goods_zpic']=='2'){
    					$v['lunbo']=$val['goods_pic'];
    			}
    		}
    	}
    	// var_dump($pic);
    	// var_dump($goods);die;
        if(session('home_id')){
            $where['uid']=session('home_id');
            $where['status']=0;
            $this->totals=M('g_cart')->where($where)->count();
        }
        $this->vos=\Home\Controller\Blog\ArticleController::datas();
        $this->link=M('link')->select();
    	$this->goods = $goods;
    	$this->vo = self::data();
    	$this->display();
    }
    public static function data(){
    	return self::lists(M('g_type')->select(),'0');
    }
    public static function lists($list,$id){
    	$res = [];
    	foreach($list as $k=>$v){
    		if($v['pid']==$id){
    			$v['sub']=self::lists($list,$v['id']);
    			$res[] = $v;
    		}
    	}
    	return $res;
    }
}